#define BLINKER_PRINT Serial
#define BLINKER_WIFI
#define BLINKER_WIFI_MULTI
// #define BLINKER_WITH_SSL
#define BLINKER_MIOT_OUTLET // 小爱 插座(outlet) 语音控制
#include <Blinker.h>
#include "eeprom_.h"
extern void open_relay();
extern void close_relay();
extern void rst();
// 新建组件对象
BlinkerButton button1("btn1");//开关
BlinkerButton button2("btn2");//getip
BlinkerButton button3("btn3");//rst
BlinkerText txt1("txt1");
// 按下按键即会执行该函数
void button1_callback(const String &state)
{
    BLINKER_LOG("get button state: ", state);
    if (state == BLINKER_CMD_ON)
    {
        open_relay();
        button1.print(BLINKER_CMD_ON);
    }
    else if (state == BLINKER_CMD_OFF)
    {
        close_relay();
        button1.print(BLINKER_CMD_OFF);
    }
}
void button2_callback(const String &state)
{
    IPAddress ip = WiFi.localIP();
    txt1.print(ip.toString());
}
void button3_callback(const String &state)
{
    BLINKER_LOG("get button state: ", state);
    rst();
    button3.print(BLINKER_CMD_OK);
}
// 如果未绑定的组件被触发，则会执行其中内容
void dataRead(const String &data)
{
    BLINKER_LOG("Blinker readString: ", data);
}

void blinker_setup()
{
#if defined(BLINKER_PRINT)
    BLINKER_DEBUG.stream(BLINKER_PRINT);
#endif

    String ssid=eeprom_get_string(SSID_INDEX);
    String pass=eeprom_get_string(PASS_INDEX);
    String auth=eeprom_get_string(BLINKER_AUTH_INDEX);
    Blinker.begin(auth.c_str(), ssid.c_str(), pass.c_str());

    Blinker.attachData(dataRead);
    button1.attach(button1_callback);
    button2.attach(button2_callback);
    button3.attach(button3_callback);
}

void blinker_loop()
{
    Blinker.run();
}